package top.btcmarket;

import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;

/**
 * @author hexj
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/4/213:50
 */
public class KeyGenerater {

    private byte[] priKey;
    private byte[] pubKey;

    public KeyGenerater() {
        try {
            java.security.KeyPairGenerator keygen = java.security.KeyPairGenerator
                    .getInstance("RSA");
            SecureRandom secrand = new SecureRandom();
            secrand.setSeed(System.currentTimeMillis()); // 初始化随机产生器
            keygen.initialize(512, secrand);
            KeyPair keys = keygen.genKeyPair();

            PublicKey pubkey = keys.getPublic();
            PrivateKey prikey = keys.getPrivate();

            pubKey = pubkey.getEncoded();
            priKey = prikey.getEncoded();

        } catch (Exception e) {
            System.out.println("生成密钥对失败");
            e.printStackTrace();
        }
    }

    public byte[] getPriKey() {
        return priKey;
    }

    public byte[] getPubKey() {
        return pubKey;
    }
}
